<template>
  <div class="app-container">
    <router-view v-slot="{ Component, route }" class="view-container">
      <transition :name="$router.customRouterData.transitionName">
        <component :is="Component" v-if="!route.meta.keepAlive" :key="route.name" />
        <keep-alive v-else>
          <component :is="Component" :key="route.name" />
        </keep-alive>
      </transition>
    </router-view>
  </div>
</template>

<script lang="ts" setup>
import { ref, computed, onMounted, watch } from "vue";
import { ElIcon, ElTabs, ElTabPane } from "element-plus";
import { useRouter, useRoute } from "vue-router";
import { useStore } from "vuex";
import { callApi } from "./tool/server";

const router = useRouter();
const route = useRoute();
const store = useStore();
store.dispatch("initializeToken");
if (store.getters.isAuthenticated) {
  callApi("Check", {}).then((res) => {
    if (!res || !res.judge) {
      store.commit("clearToken");
      router.push("/");
    }
  });
}
const navigateTo = (routeName: string) => {
  store.dispatch("navigate", { router, routeName });
};

// 新增：根据路由动态给#app加class
onMounted(() => {
  watch(
    () => route.path,
    (newPath) => {
      const app = document.getElementById('app');
      if (!app) return;
      if (newPath.startsWith('/admin')) {
        app.classList.add('admin-mode');
      } else {
        app.classList.remove('admin-mode');
      }
    },
    { immediate: true }
  );
});
</script>
<style lang="scss">
body {
  background: #222d22 !important;
  color: #fff !important;
  font-family: 'Comic Sans MS', 'Marker Felt', cursive, sans-serif;
}

html, body, #app {
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

::-webkit-scrollbar {
  width: 8px;
  background: #222d22;
}
::-webkit-scrollbar-thumb {
  background: #444e44;
  border-radius: 4px;
}

a {
  color: #ffe066;
  text-decoration: underline;
  transition: color 0.2s;
}
a:hover {
  color: #aee9f5;
}

hr, .el-divider {
  border-color: #fff !important;
}

// 粉笔色变量
:root {
  --chalk-yellow: #ffe066;
  --chalk-blue: #aee9f5;
  --chalk-pink: #ffb7c5;
  --chalk-green: #b6fcb6;
  --chalk-white: #fff;
}

.clickEffect {
  transition: transform 0.05s ease-in-out;
}

.clickEffect:active {
  transform: scale(0.98);
}
.el-button {
  transition: transform 0.05s ease-in-out;
  &:active {
    transform: scale(0.98);
  }
}

.card {
  margin: 15px auto;
  padding: 18px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

  /* 添加动画 */
  animation: fadeIn 0.5s ease-in-out;

  h1 {
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    margin: 5px 0;
    display: flex;
    align-items: center;
    justify-content: center;

    .el-icon {
      color: #409eff;
      opacity: 0.8;
      font-size: 16px;
    }
  }

  .el-button {
    margin-top: 10px;
  }

  .desc {
    font-size: 12px;
    color: #969799;
  }

  .center {
    text-align: center;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}
</style>
<style>
.el-page-header {
  height: 55px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

body {
  margin: 0;
  padding: 0;
  background: #f8f8f8;
}

.view-container {
  flex: 1;
  position: relative;
  min-height: 100vh;
}

/* 原有的过渡动画样式 */
.slide_left-enter-active,
.slide_left-leave-active,
.slide_right-enter-active,
.slide_right-leave-active {
  transition: all 0.3s;
  position: absolute !important;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 1;
  opacity: 1;
  height: 80vh;
}

.slide_left-enter-from,
.slide_right-leave-to {
  opacity: 1;
  transform: translateX(150%);
  transition: all 0.5s;
}

.slide_right-enter-from,
.slide_left-leave-to {
  opacity: 1;
  transform: translateX(-150%);
  transition: all 0.5s;
}

.slide_left-leave-to,
.slide_right-leave-to {
  opacity: 0;
}
</style>
<style lang="scss">
#app {
  width: calc(100vw - 20px);
  max-width: 420px;
  position: relative;
  min-height: calc(100vh - 20px);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  margin: 0 auto;
  padding: 0 10px;
  box-shadow: -10px 0 8px -6px rgba(0, 0, 0, 0.29), 10px 0 8px -6px rgba(0, 0, 0, 0.29);

  .app-container {
    position: relative;
    min-height: 100vh;
  }
}

body {
}

/* 隐藏进度条 */
::-webkit-scrollbar {
  display: none;
}

/* 移动端滑动优化 */
@media (max-width: 768px) {
  /* 确保所有可滑动容器在移动端正常工作 */
  .items-grid,
  .scroll_box,
  [class*="grid"],
  [class*="list"] {
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
  }
  
  /* 优化触摸反馈 */
  .item-card,
  [class*="card"] {
    touch-action: manipulation;
  }
}
</style>
<style>
#app.admin-mode {
  width: 100vw !important;
  max-width: none !important;
  margin: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
  min-height: 100vh !important;
  background: #232e23 !important;
}
</style>
<style>
.el-page-header__content {
  color: #fff !important;
  font-weight: bold;
  text-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
</style>
<style>
.el-loading-mask {
  background-color: rgba(0,0,0,0) !important;
}
</style>
